<script>
var chanID=52;
var volume = 40;
var muteFlg = false;
var timerHideVolUI;
var timerHideChanId;
var timerJoinChannel;
var speed;
var ChannelNum = "";
var isPlay = false;
var mp = new MediaPlayer();
mp.getNativePlayerInstanceID();
mp.setVideoDisplayMode(1);
mp.setVolume(volume);
mp.setAllowTrickmodeFlag(true);
mp.setAllowTrickmodeFlag(0);
mp.refreshVideoDisplay();

var tsurl = "rtsp://183.59.160.61/PLTV/88888888/224/3221226903/00000100000000060000000000480949_0.smil";
var zjtvurl = "rtsp://183.59.160.61/PLTV/88888888/224/0/3221225610/0000000007jf.smil";
mp.initMediaPlayer(1, 1, 1, 720, 1280, 0, 0, 0,0,0,100,0,0,0);
var mediaStr = '[{mediaUrl:"'+ zjtvurl +'",';
		mediaStr += 'mediaCode:"'+ 23 +'",';
		mediaStr += 'mediaType:2,';
		mediaStr += 'audioType:1,';
		mediaStr += 'videoType:1,';
		mediaStr += 'streamType:1,';
		mediaStr += 'drmType:1,';
		mediaStr += 'fingerPrint:0,';
		mediaStr += 'copyProtection:1,';
		mediaStr += 'allowTrickmode:1,';
		mediaStr += 'startTime:0,endTime:20000,entryID:"jsonentry1"}]';
		mp.setSingleMedia(mediaStr);
mp.playFromStart();
//mp.joinChannel(chanID);

function $(divid) {
	alert('get div:'+divid);
	return document.getElementById(divid);
}

function getPlayMode()
{
	var playmode = mp.getPlaybackMode();
}

function goBack()
{
	mp.leaveChannel(chanID);
	mp.stop;
	window.history.back();
}

function Enter()
{
	showChanId(chanID);
	clearTimeout(timerHideChanId);
	timerHideChanId = setTimeout("hiddeChanId()", 5000);
}

function gotoStart()
{
	mp.gotoStart();
}

function gotoEnd()
{
	mp.gotoEnd();
}

function playchan(chanID){
	showChanId(chanID);
	mp.joinChannel(chanID);
	clearTimeout(timerHideChanId);
	timerHideChanId = setTimeout("hiddeChanId()", 5000);
}

function showChanId(chanID)
{
	$("divchanId").style.display = "block";
	$("divchanId").innerHTML = chanID;
}
function hiddeChanId()
{
	$("divchanId").style.display = "none";
}

function channelUp(){
	mp.leaveChannel(chanID);
	--chanID;
	playchan(chanID)
}
function channelDown(){
	mp.leaveChannel(chanID);
	++chanID;
	playchan(chanID)
}

function showVolUI(Vol) {
	$("volbox").style.display = "block";
	alert('show vol:'+Vol);
	alert('***********show***********');
	var i=0,j=0;
	for (i = 1; i < Vol; i++);
		$("volbox"+i).style.display = "block";
	alert('***********hide***********');
	for (j = 5; j > Vol; j--)
		$("volbox"+j).style.display = "none"
	alert('***********over***********');
	clearTimeout(timerHideVolUI);
	timerHideVolUI = setTimeout("hiddeVolUI()", 5000);
}

function hiddeVolUI()
{
	$("volbox").style.display = "none";
}

function changeVol(flag){
	volume = mp.getVolume();
	volume += (flag*20);
	if (volume < 0)
		volume = 0;
	else if (volume > 100)
		volume = 100;
	mp.setVolume(parseInt(volume));
	showVolUI(volume/20);
}

function volumeUp(){
	changeVol(1);
}

function volumeDown(){
	changeVol(-1);
}

function setMute(){
	muteFlg = mp.getMuteFlag();
	mp.setMuteFlag(!muteFlg);
	if (muteFlg)
		$("volbox").style.display = "block";
	else
		hiddeVolUI();
}

function FastForward()
{
	isPlay = false;
	if (speed < 0)
		speed = 1;
	speed = speed * 2;
	mp.fastForward(speed);
}

function FastRewind()
{
	isPlay = false;
	if (speed > 1)
		speed = -1;
	speed = speed * 2;
	mp.fastRewind(speed);
}

function PlayOrPause()
{
	if (isPlay) {
		mp.pause();
		isPlay = false;
	} else {
		mp.play();
		isPlay = true;
	}
}

function Stop()
{
	mp.stop();
}

function virtialkeyEvent()
{
    alert("768");
	eval("eventJson = " + Utility.getEvent());
	
	var eventString = JSON.stringify(eventJson);
	alert("333");
	alert(eventString + "");
	
	/*
	var typeStr = eventJson.type;
	switch(typeStr)
	{	
		case "EVENT_MEDIA_ERROR":
			alert('xx1');
			return 0;
		case "EVENT_PLAYMODE_CHANGE":
			alert('xx2');
			return 0;
		case "EVENT_PLTVMODE_CHANGE":
			alert('xx3');
			return 0;
		case "EVENT_MEDIA_BEGINING":
			alert('xx4');
			return 0;
		case "EVENT_MEDIA_END":
			alert('xx5');
			return 0;
		case "EVENT_GO_CHANNEL":
			alert('xx6');
			return 0;
		case "EVENT_TVMS":
			alert('xx7');
			return 0;
		case "EVENT_TVMS_ERROR":
			alert('xx8');
			return 0;
		case "EVENT_GO_CHANNEL":
			alert('xx9');
			return 0;
		default :
			return 0;
	}
	*/
	return true;
}

function grabKeyEvent(){
	var keycode = event.which;
	alert('keycode:'+keycode+', chanID:'+chanID);
	switch(keycode){
	case 8:
		goBack();
		break;
	case 13:
		Enter();
		break;
	case 33:
		gotoStart();
		break;
	case 34:
		gotoEnd();
		break;
	case 258:
	case 40:
		channelUp();
		break;
	case 257:
	case 38:
		channelDown();
		break;
	case 48:inputNum(0) ; return true ;break ;
	case 49:inputNum(1) ; return true ;break ;
	case 50:inputNum(2) ; return true ;break ;
	case 51:inputNum(3) ; return true ;break ;
	case 52:inputNum(4) ; return true ;break ;
	case 53:inputNum(5) ; return true ;break ;
	case 54:inputNum(6) ; return true ;break ;
	case 55:inputNum(7) ; return true ;break ;
	case 56:inputNum(8) ; return true ;break ;
	case 57:inputNum(9) ; return true ;break ;
	case 259:
		volumeUp();
		break;
	case 260:
		volumeDown();
		break;
	case 261:
		setMute();
		break;
	case 263:
		PlayOrPause();
		break;
	case 264:
		FastForward();
		break;
	case 265:
		FastRewind();
		break;
	case 270:
		Stop();
		break;
	case 768:
		virtialkeyEvent();
		break;
	default:
		return false;
		break;
	}
	return true;
}
document.onkeypress = grabKeyEvent;
        
</script>

<html>
<style type="text/css">
.volboxm{ position:absolute; left:2%; top:85%; display:none;}
.volui-1 {position:absolute;left:5px;top:45px;height:10px;width:0;border-right:25px solid #e5c3b2;border-top: 10px solid transparent;}
.volui-2 {position:absolute;left:35px;top:35px;height:20px;width:0;border-right:25px solid #e5c3b2;border-top: 10px solid transparent;}
.volui-3 {position:absolute;left:65px;top:25px;height:30px;width:0;border-right:25px solid #e5c3b2;border-top: 10px solid transparent;}
.volui-4 {position:absolute;left:95px;top:15px;height:40px;width:0;border-right:25px solid #e5c3b2;border-top: 10px solid transparent;}
.volui-5 {position:absolute;left:125px;top:5px;height:50px;width:0;border-right:25px solid #e5c3b2;border-top: 10px solid transparent;}
</style>
<link href="shape.css" type="text/css" rel="stylesheet">

<head>
</head>
<body bgcolor="transparent">
<div id="divchanId" style="position:absolute; left:1160px; top:50px; font-size:50px; color:#33ff33">
</div>

<div id="" class="volboxm">
	<div id="volbox0" class="volui-0"></div>
	<div id="volbox1" class="volui-1"></div>
	<div id="volbox2" class="volui-2"></div>
	<div id="volbox3" class="volui-3"></div>
	<div id="volbox4" class="volui-4"></div>
	<div id="volbox5" class="volui-5"></div>
</div>
</body>
<script>
function inputNum(num) // 数字键
{
	ChannelNum = ChannelNum + num;
	if (ChannelNum.length == 4)
	{
		ChannelNum = num + "";
	}
	alert('ChannelNum:'+ChannelNum);
	showChanId(ChannelNum);
	clearTimeout(timerJoinChannel) ;
	timerJoinChannel = setTimeout(function(){
		if (ChannelNum.length < 4)
		{
			chanID = ChannelNum;
			playchan(chanID);
		}
		ChannelNum = "";
	},2000);
	
}
</script>
</html>